import request from '@/axios';
import {baseUrl} from '@/config/env';

export const list = (data) => {
    return request({
            url: baseUrl + '/start/actModel/page',
            method: 'get',
            params: data
        }
    )
}


export const add = (data) => {
    return request({
            url: baseUrl + '/start/actModel/add',
            method: 'post',
            data: data
        }
    )
}

export const updateById = (data) => {
    return request({
            url: baseUrl + '/start/actModel/updateById',
            method: 'put',
            data: data
        }
    )
}
export const deleteById = (id) => {
    return request({
            url: baseUrl + '/start/actModel/deleteById/' + id,
            method: 'delete',
        }
    )
}
export const getById = (id) => {
    return request({
            url: baseUrl + '/start/actModel/getById/' + id,
            method: 'get',
        }
    )
}

export const getActModelConfigDetail = (id) => {
    return request({
            url: baseUrl + '/start/actModel/getActModelConfigDetail/' + id,
            method: 'get',
        }
    )
}

export const saveModelEditorSource = (id, data) => {
    return request({
            url: baseUrl + '/start/actModel/saveModelEditorSource/' + id,
            method: 'post',
            data: data
        }
    )
}

/**
 * 部署流程模型
 * @param id
 * @returns {AxiosPromise}
 */
export const deploymentModel = (id) => {
    return request({
            url: baseUrl + '/start/actModel/deploymentModel/' + id,
            method: 'get',
        }
    )
}
/**
 * 获取模型配置
 * @param id
 * @returns {AxiosPromise}
 */
export const getModelConfig = (id) => {
    return request({
            url: baseUrl + '/start/actModel/getModelConfig/' + id,
            method: 'get',
        }
    )
}
/**
 * 获取模型配置
 * @param id
 * @returns {AxiosPromise}
 */
export const getAllGroupModels = () => {
    return request({
            url: baseUrl + '/start/actModel/getAllGroupModels',
            method: 'get',
        }
    )
}

function saveModel(data) {
    if (data.id) {
        return updateById(data)
    }
    return add(data)
}

/**
 * 获取流程模型部署历史
 * @param data
 * @returns {Promise<AxiosResponse<any>> | *}
 */
export const getModelDeployHistory = (data) => {

    return request({
            url: baseUrl + '/start/actModel/getModelDeployHistory/' + data.procDeployDefKey,
            method: 'get',
            params: data
        }
    )
}
/**
 * 修改已部署模型状态
 * @param deployDefId
 * @param status
 * @returns {Promise<AxiosResponse<any>> | *}
 */
export const updateDeployDefStatus = (deployDefId, status) => {

    return request({
            url: baseUrl + '/start/actModel/updateDeployDefStatus/' + deployDefId,
            method: 'get',
            params: {status: status}
        }
    )
}
/**
 * 根据流程模型key获取流程模型全部用户任务
 * @param modelId
 * @returns {Promise<AxiosResponse<any>> | *}
 */
export const getModelTasksByModelId = (modelId) => {
    return request({
            url: baseUrl + '/start/actModel/getModelTasksByModelId/' + modelId,
            method: 'get',

        }
    )
}
/**
 * 获取流程模型主表单 在各个任务节点的配置
 * @param modelId
 * @returns {Promise<AxiosResponse<any>> | *}
 */
export const getActFormPropConfigByModelId = (modelId) => {
    return request({
            url: baseUrl + '/start/actModel/getActFormPropConfigByModelId/' + modelId,
            method: 'get',

        }
    )
}
/**
 * 保存流程模型主表单 在各个任务节点的配置
 * @param modelId
 * @param config
 * @returns {*}
 */
export const saveActFormPropConfigByModelId = (modelId, config) => {
    return request({
            url: baseUrl + '/start/actModel/saveActFormPropConfigByModelId/' + modelId,
            method: 'post',
            data: config
        }
    )
}

/**
 * 根据流程部署id获取流程模型全部用户任务
 * @param deployId
 * @returns {Promise<AxiosResponse<any>> | *}
 */
export const getModelTasksByDeployId = (deployId) => {
    return request({
            url: baseUrl + '/start/actModel/getModelTasksByDeployId/' + deployId,
            method: 'get',

        }
    )
}
/**
 * 根据流程部署id获取已部署流程模型主表单 在各个任务节点的配置
 * @param deployId
 * @returns {Promise<AxiosResponse<any>> | *}
 */
export const getActFormPropConfigByDeployId = (deployId) => {
    return request({
            url: baseUrl + '/start/actModel/getActFormPropConfigByDeployId/' + deployId,
            method: 'get',

        }
    )
}
/**
 * 根据流程部署id 保存已部署流程模型主表单 在各个任务节点的配置
 * @param deployId
 * @param config
 * @returns {*}
 */
export const saveActFormPropConfigByDeployId = (deployId, config) => {
    return request({
            url: baseUrl + '/start/actModel/saveActFormPropConfigByDeployId/' + deployId,
            method: 'post',
            data: config
        }
    )
}
/**
 * 获取全局功能配置
 * @returns {Promise<AxiosResponse<any>> | *}
 */
export const listGlobalActFunDefCategoryDetail = () => {
    return request({
            url: baseUrl + '/start/actModel/listGlobalActFunDefCategoryDetail',
            method: 'get',
        }
    )
}

/**
 * 保存流程功能配置
 * @param deployDefId 流程部署定义id
 * @param configs 配置值
 * @returns {Promise<AxiosResponse<any>> | *}
 */
export const saveProcFunDefConfVals = (deployDefId, configs) => {
    return request({
            url: baseUrl + '/start/actModel/saveProcFunDefConfVals/' + deployDefId,
            method: 'post',
            data: configs
        }
    )
}
/**
 * 根据流程部署定义id 获取流程功能定义
 * @param deployDefId
 * @returns {Promise<AxiosResponse<any>> | *}
 */
export const getProcFunConfigByDeployDefId = (deployDefId) => {
    return request({
            url: baseUrl + '/start/actModel/getProcFunConfigByDeployDefId/' + deployDefId,
            method: 'get',

        }
    )
}


const actModelApi = {
    list,
    saveModel,
    getById,
    updateById,
    getModelConfig,
    deploymentModel,
    getAllGroupModels,
    getActModelConfigDetail,
    getModelDeployHistory,
    updateDeployDefStatus,
    getModelTasksByModelId,
    getActFormPropConfigByModelId,
    saveActFormPropConfigByModelId,
    getModelTasksByDeployId,
    getActFormPropConfigByDeployId,
    saveActFormPropConfigByDeployId,
    listGlobalActFunDefCategoryDetail,
    saveProcFunDefConfVals,
    getProcFunConfigByDeployDefId
}
export default actModelApi
